<template>
  <div class="container">
    <!--  <el-button
      style="margin: 12px 12px 0 12px"
      type="primary"
      size="small"
      @click="handleReturn"
      >返 回</el-button
    > -->

    <baleTable
      :tableData="tableData"
      :tableHead="tableHead"
      :isSearch="true"
      :tableLoading="tableLoading"
      :page="page"
      @pageSizeChange="pageSizeChange"
      @handleCurrentChange="handleCurrentChange"
      @searchMethods="searchMethods"
      @tableSortChange="tableSortChange"
      ref="baleTable"
    >
      <template #tableOperation="{ scope }">
        <el-button
          type="primary"
          :disabled="scope.row.status != '待审核'"
          @click="quDetailSubmit(scope.row)"
          :loading="btnLoading"
          size="small"
          >审 核</el-button
        >
      </template>
    </baleTable>
    <quDetailDialogVue ref="quDetail" @refresh="getUserList" />
  </div>
</template>

<script>
import { debounce } from "@/util";
import { ApiUserEdit, ApiQualificationList } from "@/api/index.js";
import ImgUploadPath from "@/components/imgUpload-path.vue";
import { validatePhone } from "@/util/validate";
import { tableHead } from "./config.js";
import quDetailDialogVue from "./quDetailDialog.vue";
export default {
  props: ["roleData", "departmentData"],
  components: {
    ImgUploadPath,
    quDetailDialogVue,
  },
  data() {
    return {
      tableData: [],
      tableHead,
      validatePhone,
      oldform: {
        nick_name: "",
        phone: "",
        gender: "",
        icon: "",
        /*    unit: "京山市人民医院", */
      },
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      form: {},
      btnLoading: false,
      dialogVisible: false,
      tableLoading: false,
      id: null,
      title: "",
      imgsDefalut: [],
      sortParams: {},
      statusFormatter: [
        {
          name: "待支付",
          code: "1",
          type: "danger",
        },
        {
          name: "待接单",
          code: "2",
          type: "",
        },
        {
          name: "已接单",
          code: "3",
          type: "warning",
        },
        {
          name: "已出发",
          code: "4",
          type: "warning",
        },
        {
          name: "已上门",
          code: "5",
          type: "warning",
        },
        {
          name: "已完成",
          code: "6",
          type: "success",
        },
        {
          name: "已取消",
          code: "7",
          type: "danger",
        },
        {
          name: "已评价",
          code: "8",
          type: "success",
        },
      ],
    };
  },

  mounted() {
    this.getUserList();
  },

  methods: {
    searchMethods(params) {
      this.searchParams = {};
      this.page.page = 1;
      this.searchParams = params;
      this.getUserList(this.$route.params.id);
    },
    pageSizeChange(val) {
      this.page.size = val;
      this.getUserList(this.$route.params.id);
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getUserList(this.$route.params.id);
    },
    tableSortChange(params) {
      if (params.sort_str) {
        this.sortParams = { ...this.sortParams, ...params };
      } else {
        delete this.sortParams.sort_str;
        delete this.sortParams.sort_order;
      }
      this.page.page = 1;
      this.getUserList();
    },

    onUploadSuccess(path) {
      this.form.icon = path;
    },
    onUploadRemove() {
      this.form.icon = "";
    },
    confirm: debounce(
      function () {
        this.$refs["formRef"].validate(async (valid) => {
          if (valid) {
            this.btnLoading = true;

            try {
              if (this.id) {
                await ApiUserEdit(this.form, this.id);
                this.$message.success("修改成功");
              } else {
                const form = { ...this.form, password: "123456" };
                await ApidoctorAdd(form);
                this.$alert("添加成功，该员工初始密码为：123456", "提示", {
                  confirmButtonText: "确定",
                  callback: (action) => {},
                });
              }

              this.handleClose();
              this.$emit("refresh");
            } finally {
              this.btnLoading = false;
            }
          } else return false;
        });
      },
      500,
      true
    ),

    //获取用户数据
    getUserList() {
      let postParams = {
        ...this.searchParams,
        ...this.sortParams,
        ...this.page,
      };
      this.tableLoading = true;
      ApiQualificationList(postParams).then((res) => {
        let { data, page } = res;
        this.tableData = data;
        this.page.total = page.total;
        this.tableLoading = false;
      });
    },

    quDetailSubmit(e) {
      this.$refs.quDetail.show(e);
    },
  },
};
</script>

<style></style>
